import request from '@/utils/request'

/**
 * 管理员登录
 */
export const login = (data) => {
  return request({
    url: '/admin/auth/login',
    method: 'post',
    data
  })
}

/**
 * 刷新Token
 */
export const refreshToken = (refreshToken) => {
  return request({
    url: '/admin/auth/refresh',
    method: 'post',
    data: { refreshToken }
  })
}

/**
 * 退出登录
 */
export const logout = () => {
  return request({
    url: '/admin/auth/logout',
    method: 'post'
  })
}

/**
 * 验证Token
 */
export const validateToken = () => {
  return request({
    url: '/admin/auth/validate',
    method: 'get'
  })
}

// 院校管理
/**
 * 获取院校列表
 */
export const getAdminSchools = (params) => {
  return request({
    url: '/admin/schools',
    method: 'get',
    params
  })
}

/**
 * 获取院校详情
 */
export const getAdminSchool = (id) => {
  return request({
    url: `/admin/schools/${id}`,
    method: 'get'
  })
}

/**
 * 创建院校
 */
export const createSchool = (data) => {
  return request({
    url: '/admin/schools',
    method: 'post',
    data
  })
}

/**
 * 更新院校
 */
export const updateSchool = (id, data) => {
  return request({
    url: `/admin/schools/${id}`,
    method: 'put',
    data
  })
}

/**
 * 删除院校
 */
export const deleteSchool = (id) => {
  return request({
    url: `/admin/schools/${id}`,
    method: 'delete'
  })
}

/**
 * 更新院校状态
 */
export const updateSchoolStatus = (id, status) => {
  return request({
    url: `/admin/schools/${id}/status`,
    method: 'put',
    params: { status }
  })
}

// 文章管理
/**
 * 获取文章列表
 */
export const getAdminArticles = (params) => {
  return request({
    url: '/admin/articles',
    method: 'get',
    params
  })
}

/**
 * 获取文章详情
 */
export const getAdminArticle = (id) => {
  return request({
    url: `/admin/articles/${id}`,
    method: 'get'
  })
}

/**
 * 创建文章
 */
export const createArticle = (data) => {
  return request({
    url: '/admin/articles',
    method: 'post',
    data
  })
}

/**
 * 更新文章
 */
export const updateArticle = (id, data) => {
  return request({
    url: `/admin/articles/${id}`,
    method: 'put',
    data
  })
}

/**
 * 删除文章
 */
export const deleteArticle = (id) => {
  return request({
    url: `/admin/articles/${id}`,
    method: 'delete'
  })
}

/**
 * 发布文章
 */
export const publishArticle = (id) => {
  return request({
    url: `/admin/articles/${id}/publish`,
    method: 'put'
  })
}

/**
 * 下线文章
 */
export const unpublishArticle = (id) => {
  return request({
    url: `/admin/articles/${id}/unpublish`,
    method: 'put'
  })
}

// 分类管理
/**
 * 获取分类列表
 */
export const getAdminCategories = () => {
  return request({
    url: '/admin/categories',
    method: 'get'
  })
}

/**
 * 创建分类
 */
export const createCategory = (data) => {
  return request({
    url: '/admin/categories',
    method: 'post',
    data
  })
}

/**
 * 更新分类
 */
export const updateCategory = (id, data) => {
  return request({
    url: `/admin/categories/${id}`,
    method: 'put',
    data
  })
}

/**
 * 删除分类
 */
export const deleteCategory = (id) => {
  return request({
    url: `/admin/categories/${id}`,
    method: 'delete'
  })
}